package com.solweaver.greetings.utils;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;

public class JsonDateDeSerializer extends JsonDeserializer<Timestamp>{

	@Override
    public Timestamp deserialize(JsonParser jsonparser,
            DeserializationContext deserializationcontext) throws IOException, JsonProcessingException {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
		//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String dateStr = jsonparser.getText();
        try {
        	Date date = format.parse(dateStr);
        	Timestamp timeStamp = new Timestamp(date.getTime());
            return timeStamp;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

    }
}

